package com.gl.saasservice.repository;


import com.gl.saasservice.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {

    Role findByCode(String code);

    Role findByName(String name);

    List<Role> findByIdIn(List<Long> roleIdList);

    List<Role> findByOrgId(Long orgId);

    List<Role> findByOrgIdAndPropertyAndType(Long orgId, Integer property, Integer type);

    List<Role> findByOrgIdInAndTypeAndProperty(List<Long> orgIds, Integer type, Integer property);

    @Query(value = "SELECT * FROM saas_role WHERE org_id = ?1 AND property = 2 AND TYPE != 1", nativeQuery = true)
    List<Role> selectOtherRole(Long orgId);
}
